package com.example.jikejavatrain.jvm;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

public class CustomerClassLoader extends ClassLoader{

    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        new CustomerClassLoader().findClass("Hello").newInstance();
        System.out.println("执行结束");

    }

    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
        byte[] readAllBytes = null;
        try {
           readAllBytes = Files.readAllBytes(new File("E:\\jike-javaTrain\\src\\main\\java\\com\\example\\jikejavatrain\\jvm\\Hello.xlass").toPath());
        } catch (IOException e) {
            e.printStackTrace();
        }
        byte[] resolveBytes = null;
        if(readAllBytes != null){
            resolveBytes = new byte[readAllBytes.length];
            for (int i = 0; i < readAllBytes.length; i++) {
                byte readAllByte = readAllBytes[i];
                byte b = (byte) (255 - readAllByte);
                resolveBytes[i] = b;
            }
        }

        return defineClass(name,resolveBytes,0,resolveBytes.length);
    }
}
